package com.company.server;

import com.company.common.Message;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class MessageDao {
    private static final Map<String, List<Message>> OFFLINE_MAP = new ConcurrentHashMap<>();

    public static List<Message> get(String username) {
        return OFFLINE_MAP.get(username);
    }

    public static void add(Message message) {
        List<Message> messages = OFFLINE_MAP.get(message.getReceiver());
        if (messages == null) {
            messages = new ArrayList<>();
        }
        messages.add(message);
        OFFLINE_MAP.put(message.getReceiver(), messages);
    }

    public static void delete(String username) {
        OFFLINE_MAP.remove(username);
    }
}
